package com.gdones.wms.bus.outbound.controller;


import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import com.gdones.wms.bus.outbound.dto.OutBoundDto;
import com.gdones.wms.bus.outbound.dto.WmsOutbound;
import com.gdones.wms.bus.outbound.service.IWmsOutboundService;
import com.gdones.wms.bus.record.dto.WmsRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 仓储出库记录主表 前端控制器
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-05-08
 */
@RestController
@RequestMapping("/outbound")
@Slf4j
@Api(tags = "物资出库")
public class WmsOutboundController {

    @Resource(name = "wmsOutboundServiceImpl")
    private IWmsOutboundService wmsOutboundService;

    @GetMapping("/pages")
    @ApiOperation("物资出库-分页")
    @MySysLog(modelName="物资出库",methodDesc = "分页",methodType = MySysLogOpration.GET)
    public MyResult pages(WmsOutbound dto, MyPageBand pageBand){

        log.debug("--物资出库：分页");
        MyResult result = new MyResult();

        try {
            result = wmsOutboundService.pages(dto,pageBand);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资出库-分页-异常");
        }
        return result;
    }

    @GetMapping("/list")
    @ApiOperation("物资出库-列表（不分页）")
    @MySysLog(modelName="物资出库",methodDesc = "列表（不分页）",methodType = MySysLogOpration.GET)
    public MyResult pages(WmsOutbound dto){

        log.debug("--物资出库：列表（不分页）");
        MyResult result = new MyResult();

        try {
            result =wmsOutboundService.list(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资出库-列表（不分页）-异常");
        }
        return result;
    }

    @GetMapping("/getByID")
    @ApiOperation("物资出库-查看出库单详情")
    @MySysLog(modelName="物资出库",methodDesc = "查看出库单详情",methodType = MySysLogOpration.GET)
    public MyResult getByID(String id){

        log.debug("--物资出库：查看出库单详情");
        MyResult result = new MyResult();

        try {
            result =wmsOutboundService.getByID(id);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资出库-查看出库单详情-异常");
        }
        return result;
    }

    @PostMapping("/add")
    @ApiOperation("物资出库-添加")
    @MySysLog(modelName="物资出库",methodDesc = "添加",methodType = MySysLogOpration.POST)
    public MyResult add(@RequestBody OutBoundDto dto){

        log.debug("--物资出库：添加");
        MyResult result = new MyResult();

        try {
            result = wmsOutboundService.add(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资出库-添加-异常");
        }
        return result;
    }

    @DeleteMapping("/deletes")
    @ApiOperation("物资出库-删除")
    @MySysLog(modelName="物资出库",methodDesc = "删除",methodType = MySysLogOpration.DELETE)
    public MyResult deletes(String ids){

        log.debug("--物资出库：删除");
        MyResult result = new MyResult();

        try {
            result = wmsOutboundService.deletes(ids);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资出库-删除-异常");
        }

        return result;
    }

}
